package com.jie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jie.entity.OperationLog;
import com.jie.mapper.OperationLogMapper;
import com.jie.service.OperationLogService;
import com.jie.utils.PageUtils;
import com.jie.utils.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("OperationLogService")
public class OperationLogServiceImpl  extends ServiceImpl<OperationLogMapper, OperationLog> implements OperationLogService {
    @Autowired
    private OperationLogService operationLogService;

    @Override
    public R limit(Long page, Long limit) {
        Page<OperationLog> pageParam = new Page<>(page,limit);
        operationLogService.page(pageParam,null);
        long total = pageParam.getTotal();
        List<OperationLog> records = pageParam.getRecords();
        return  R.ok().data("total", total).data("rows", records);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String userName = (String)params.get("username");
        String createDate = (String)params.get("createDate");
        IPage<OperationLog> page = this.page(
                new Query<OperationLog>().getPage(params),
                new QueryWrapper<OperationLog>()
                        .like(StringUtils.isNotBlank(userName),"username", userName)
                        .like(StringUtils.isNotBlank(createDate),"create_date", createDate));
        return new PageUtils(page);
    }


    private class Query<T> {
        public IPage<T> getPage(Map<String, Object> params) {
            Page<T> page=new Page<>();
            return page;
        }
    }
}
